<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>采购件新增</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
</head>
<body>
	<div id="msg" align="center" style="padding-top: 40px;">
		正在验证物料编码……</div>
	<script type="text/javascript">
	
		var upWindow = window.parent.frames["zwIframe"];
		var designClass = "design_class", hideClass = "hide_class", browseClass = "browse_class", addClass = "add_class", editClass = "edit_class";
	
		function fy_dialog_close() {
			window.parent.$(".mask").remove();
			window.parent.parent.$(".layui-layer-iframe").parent().find(".layui-layer-close").trigger("click");
		
		}
		function getUpFieldsByFieldval(name) {
			return upWindow.$("[fieldval*='displayName:\"" + name + "\"']");
			
		}

		function getUpFieldValue(field) {
		
			var fieldVal = field.attr("fieldVal");
			var editTag = field.hasClass(editClass);
			var browseTag = field.hasClass(browseClass);
			var addTag = field.hasClass(addClass);
			if (fieldVal != null && typeof (fieldVal) != 'undefined') {
				fieldVal = eval("(" + fieldVal + ")");
			} else {
				return null;
			}
			var obj = new Object();
			obj.displayName = fieldVal.displayName;
			obj.name = fieldVal.name;
			var tag = true;
			switch (fieldVal.inputType) {
			case "text":
			case "textarea":
				if (editTag) {
					obj.value = field.find("#" + fieldVal.name).val();
				} else if (browseTag) {
					obj.value = fieldVal.value;
				} else if (addTag) {
					obj.value = field.find("#" + fieldVal.name).val();
				}
				break;
			default:
				tag = false;
			}
			if (obj.value != undefined) {
				obj.value = obj.value.replace("\r\n", ";");
				obj.value = obj.value.replace("\n", ";");
			}
			return obj;
		}

		function setUpFieldValue2(field, value, displayValue, index) {
		
			var fieldVal = field.attr("fieldVal");
			var editTag = field.hasClass(editClass);
			var browseTag = field.hasClass(browseClass);
			var addTag = field.hasClass(addClass);
			if (fieldVal != null && typeof (fieldVal) != 'undefined') {
				fieldVal = eval("(" + fieldVal + ")");
			} else {
				return null;
			}
			var tag = true;
			switch (fieldVal.inputType) {
			case "text":
			case "textarea":
				if (editTag) {
					field.find("#" + fieldVal.name).val(value);
					field.find("#" + fieldVal.name).trigger("blur");
				} else if (addTag) {
					field.find("#" + fieldVal.name).val(
							field.find("#" + fieldVal.name).val() + value);
					field.find("#" + fieldVal.name).trigger("blur");
				}
				break;
			case "date":
				if (editTag) {
					field.find("#" + fieldVal.name).val(value);
					field.find("#" + fieldVal.name).trigger("blur");
				}
				break;
			}
		}


		var ITEM=[];
		var xmlObj = null;
		
		var ITEMArray=getUpFieldsByFieldval("ITEM");
		var ProjectDescriptionArray=getUpFieldsByFieldval("材料名称项目说明");
		//var SpecificationTypeArray=getUpFieldsByFieldval("材料型号规格");
		var UnitArray=getUpFieldsByFieldval("单位");
		
		if (ITEMArray.length > 0) {
			
			length = ITEMArray.length;
			
		} 
		
		function init() {
	
			for (var i = 0; i < length; i++) {
			ITEM.push(getUpFieldValue(ITEMArray.eq(i)).value);
			setUpFieldValue2(ProjectDescriptionArray.eq(i), "");
			//setUpFieldValue2(SpecificationTypeArray.eq(i), "");
			setUpFieldValue2(UnitArray.eq(i), "");
			}
		}

		function load() {
	
			if (window.XMLHttpRequest) {
				xmlObj = new XMLHttpRequest();
			} else {
				if (window.ActiveXObject) {
					xmlObj = new ActiveXObject("Microsoft.XMLHTTP");//java定义XMLHTTP对象的方法
				} else {
					return;
				}
			}
			xmlObj.onreadystatechange = handleResponse;
			xmlObj.open("get",
					"./oa2mdmController.do?method=writePurchasePartsJSP&ITEM="
							+ ITEM.join(","), true);
			
			xmlObj.send();//发送
			//alert(fiexdCode.join(","));

		}

		function handleResponse() {
			
			if (xmlObj.readyState == 4) {//xmlObj loaded		
				var success = false;
			//	alert(xmlObj.status+"@@");				
				if (xmlObj.status == 200) {	
			//	alert(xmlObj.responseText+"##");	
					var datas = eval("[" + xmlObj.responseText + "]");
				//	alert(datas.length+"()");
					if (datas.length == 1) {
						var materialMap = datas[0];
						
						
						for (var i = 0; i < length; i++) {							
								var material = materialMap["ITEM"
										+ getUpFieldValue(ITEMArray
												.eq(i)).value];
												
								if (material) {
									setUpFieldValue2(ProjectDescriptionArray
											.eq(i), material["ProjectDescription"]);//材料名称项目说明
									setUpFieldValue2(UnitArray
											.eq(i), material["Unit"]);//单位
								}
							
							success = true;
						}

					}
				}
				if (!success) {
					alert("请检查输入的ITEM ");
				}
				fy_dialog_close();
			}

		}
		init();//初始化
		load();//加载
	</script><html></html>
</body>
</html>

